<template>
	<view class="content">
		<nav-bar title="优惠券详情"></nav-bar>
		<view class="card">
			<view class="card-item" :style="{ background: `url(${baseImgUrl}img_coupon_bg2.png)` }">
				<view class="left">
					<view class="money-once" v-if="couponTopDetail.discountsType == 1">
						<span class="money-item">{{couponTopDetail.discountRate }}</span>折
					</view>
					<view class="money-once" v-if="couponTopDetail.discountsType == 2">
						￥<span class="money-item">{{ couponTopDetail.discountAmount }}</span>
					</view>
					<view class="money-twice">
						满￥{{ couponTopDetail.fullAmount }}可用
					</view>
				</view>
				<view class="right">
					<view class="right-content">
						<view class="right-title">
							{{ couponTopDetail.name }}
						</view>
						<view class="right-time">
							<!-- {{ couponTopDetail.effectiveTime }}到期 -->
							优惠类型：{{couponDetail.couponType}}
						</view>
						<view class="right-type">
							<!-- {{ couponTopDetail.couponTypeName }} -->
						</view>
					</view>
					<view class="not-use-btn" v-if="status === 0 && couponTopDetail.ifUse" @click="clickToUse">去使用
					</view>
					<view class="use-btn" v-if="status === 2">已使用</view>
				</view>
			</view>
		</view>

		<view class="word">
			<scroll-view scroll-y="true" :style="{ height:mainHeight}">
				<view class="card-title">{{ couponDetail.name }}</view>
				<view class="list">
					<li v-for="(item, index) in detailConfig" :key="index">
						<view class="list-item">
							<view class="img">
							</view>
							<view class="title">
								{{ item.label }}
							</view>
						</view>
						<view class="content" v-if="item.key=='ableMaxdiscountAmount'">
							{{ couponDetail[item.key] ?couponDetail[item.key] + '元':'暂无' }}
						</view>
						<view class="content" v-else>
							<view
								v-if="!isExpanded && couponDetail[item.key] && couponDetail[item.key].length > maxLength">
								{{ couponDetail[item.key].slice(0, maxLength) }}...
								<span @click="isExpanded = true" class="more-btn">查看更多</span>
							</view>
							<view v-else>
								{{ couponDetail[item.key] || '暂无' }}
								<span v-if="isExpanded && couponDetail[item.key] && couponDetail[item.key].length > maxLength" @click="isExpanded = false" class="more-btn">收起</span>
							</view>
							<!-- {{ couponDetail[item.key] || '暂无' }} -->
						</view>
					</li>
				</view>
			</scroll-view>

		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/nav-bar/index.vue'
	import api_mine from '@/api/mine'
	import pageConfig from '@/config'
	export default {
		components: {
			NavBar,
		},
		data() {
			return {
				baseImgUrl: pageConfig.baseImgUrl,
				couponTopDetail: {},
				mainHeight: '',
				couponId: '',
				status: '',
				couponDetail: {},
				isExpanded: false,
				maxLength: 200, // 可根据需求调整最大显示长度
				detailConfig: [{
						label: '最高可减',
						key: 'ableMaxdiscountAmount'
					},
					{
						label: '适用门店',
						key: 'storeString'
					},
					{
						label: '适用项目',
						key: 'itemString'
					},
					{
						label: '可使用日期(周期)',
						key: 'dayOrWeek'
					},
					{
						label: '可使用时间段',
						key: 'useTime'
					},
					{
						label: '有效期',
						key: 'effectiveTime'
					},
					{
						label: '规则说明',
						key: 'ruleDesc'
					}
				]
			}
		},
		onLoad(options) {
			const deco = JSON.parse(decodeURIComponent(options.params));
			this.couponTopDetail = deco
			this.status = Number(deco.status)
			this.couponId = deco.id
			this.getCouponDetail()
		},
		created() {
			this.mainHeight = this.$store.getters.heightData.mainHeight.split('px')[0] - 200 + 'px'
		},
		methods: {
			getCouponDetail() {
				api_mine.fetchCouponDetail(this.couponId).then(res => {
					if (res.code !== 200) return
					// res.data.effectiveTime = res.data.effectiveTime.split('.')[0].replace('T', ' ')
					this.couponDetail = res.data
				})
			},
			clickToUse() {
				uni.switchTab({
					url: '/pages/technician/index'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.card {
		padding: 32rpx;
		background-color: #fff;

		.card-item {
			width: 673rpx;
			height: 213rpx;
			background-size: cover !important;
			background-position: center !important;
			margin-top: 24rpx;
			display: flex;

			.left {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				width: 189rpx;
				color: #FFFFFF;

				.money-once {
					.money-item {
						font-size: 72rpx;
						font-family: DIN, DIN;
						font-weight: bold;
					}
				}

				.money-twice {
					font-size: 22rpx;
				}
			}

			.right {
				width: 484rpx;
				padding: 0 32rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.right-content {
					font-family: Source Han Sans CN, Source Han Sans CN;

					.right-title {
						font-size: 34rpx;
						font-weight: bold;
						color: #333333;
						line-height: 45rpx;
					}

					.right-time {
						margin: 6rpx 0;
						font-size: 24rpx;
						font-weight: 400;
						color: #666666;
						line-height: 36rpx;
					}

					.right-type {
						font-size: 24rpx;
						font-weight: 400;
						color: #666666;
						line-height: 36rpx;
					}

					.right-rule {
						font-size: 24rpx;
						font-weight: 500;
						color: #C27E15;
						line-height: 36rpx;
					}
				}

				.not-use-btn,
				.use-btn {
					width: 128rpx;
					height: 55rpx;
					font-size: 26rpx;
					text-align: center;
					color: #FFFFFF;
					line-height: 55rpx;
					font-family: Source Han Sans CN, Source Han Sans CN;
					font-weight: 500;
					background: linear-gradient(90deg, #FF9241 0%, #FF7003 100%);
					border-radius: 42rpx 42rpx 42rpx 42rpx;
					opacity: 1;
				}

				.use-btn {
					background: #b1b1b1;
				}
			}
		}
	}

	.word {
		background-color: #fff;
		margin-top: 32rpx;
		padding: 32rpx;

		.card-title {
			font-size: 36rpx;
			font-weight: 600;
			font-family: Source Han Sans CN, Source Han Sans CN;
		}

		.list {
			padding: 12rpx 2rpx 0;

			li {
				padding: 16rpx;

				.list-item {
					display: flex;

					.img {
						width: 20rpx;
						height: 20rpx;
						border: 5rpx solid #C27E15;
						border-radius: 16rpx;
						margin-top: 10rpx;
					}

					.title {
						margin-left: 20rpx;
						font-size: 30rpx;
						font-weight: 500;
					}
				}

				.content {
					margin-left: 30rpx;
					line-height: 38rpx;
					padding: 16rpx;
					word-break: break-all;
				}

			}

		}
	}
	.more-btn {
	  color: #c27e15;
	  cursor: pointer;
	  margin-left: 5px;
	}
</style>